package com.yanfan.data.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.iot.domain.DeviceDept;
import com.yanfan.iot.service.IDeviceDeptService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 设备部门中间表Controller
 *
 * @author kerwincui
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/iot/dept")
@Api(tags = "设备部门中间表")
public class DeviceDeptController extends BaseController {
    @Autowired
    private IDeviceDeptService deviceDeptService;

    /**
     * 查询设备部门中间表列表
     */
    @PreAuthorize("@ss.hasPermi('iot:dept:list')")
    @GetMapping("/list")
    @ApiOperation("查询设备部门中间表列表")
    public TableDataInfo list(DeviceDept deviceDept) {
        startPage();
        List<DeviceDept> list = deviceDeptService.selectDeviceDeptList(deviceDept); return getDataTable(list);
    }

    /**
     * 导出设备部门中间表列表
     */
    @ApiOperation("导出设备部门中间表列表")
    @PreAuthorize("@ss.hasPermi('iot:dept:export')")
    @Log(title = "设备部门中间表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceDept deviceDept) {
        List<DeviceDept> list = deviceDeptService.selectDeviceDeptList(deviceDept);
        ExcelUtil<DeviceDept> util = new ExcelUtil<DeviceDept>(DeviceDept. class);
        util.exportExcel(response, list, "设备部门中间表数据");
    }

    /**
     * 获取设备部门中间表详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:dept:query')")
    @GetMapping(value = "/{deptId}")
    @ApiOperation("获取设备部门中间表详细信息")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId) {
        return success(deviceDeptService.selectDeviceDeptByDeptId(deptId));
    }

    /**
     * 新增设备部门中间表
     */
    @PreAuthorize("@ss.hasPermi('iot:dept:add')")
    @Log(title = "设备部门中间表", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增设备部门中间表")
    public AjaxResult add(@RequestBody DeviceDept deviceDept) {
        return toAjax(deviceDeptService.insertDeviceDept(deviceDept));
    }

    /**
     * 修改设备部门中间表
     */
    @PreAuthorize("@ss.hasPermi('iot:dept:edit')")
    @Log(title = "设备部门中间表", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改设备部门中间表")
    public AjaxResult edit(@RequestBody DeviceDept deviceDept) {
        return toAjax(deviceDeptService.updateDeviceDept(deviceDept));
    }

    /**
     * 删除设备部门中间表
     */
    @PreAuthorize("@ss.hasPermi('iot:dept:remove')")
    @Log(title = "设备部门中间表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptIds}")
    @ApiOperation("删除设备部门中间表")
    public AjaxResult remove(@PathVariable Long[] deptIds) {
        return toAjax(deviceDeptService.deleteDeviceDeptByDeptIds(deptIds));
    }
}
